Page({
  data: {
    dialogVisible: false,
    houseList:[]
  },

  swipeClose(ev) {
    const { position, instance } = ev.detail
     console.log(ev);
    if (position === 'right') {
      // 拿到当前数据的id
       this.id = ev.mark.id
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })

      // swiper-cell 滑块关闭
      instance.close()
    }
  },

 async dialogClose(e){
    // const { position, instance } = ev.detail
    console.log(e);
    //删除功能
     if(e.detail === 'confirm'){
       const res = await wx.http({
         method:'delete',
         url:`/room/${this.id}`
       })
       console.log(res);
      // 获取数据重新渲染
       const ress = await  wx.http({
        url:"/room"
      })
      console.log(res);
      this.setData({houseList:ress.data})
     }
     wx.showToast({
      title:'删除成功',
      icon:'success'
     })
  },

  goDetail(e) {
    console.log(e);
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + e.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
 async onLoad(){
   const res = await  wx.http({
      url:"/room"
    })
    console.log(res);
    this.setData({houseList:res.data})
  }
})
